<?php
namespace App\Libs\Base;
use Phalcon\Mvc\Model;
class BaseModel extends Model
{
	protected $__TABLE__ = '';
	public function initialize() {
		$this->setReadConnectionService("dbSlave");

		$this->setWriteConnectionService("dbMaster");
		$this->setSource($this->__TABLE__);
	}
	public static function findOne($parameters = null){
		return self::findFirst($parameters);
	}

	public static function findAll ($parameters = null) {
		return parent::find($parameters);
	}
	
	/**
	*	跳过检测 数据库有默认值的
	*/
	public static function skipValidation( $skipers=[] , $user ){
		foreach ($skipers as $skiper) {
			if(empty($user->$skiper)) {
				$user->$skiper = new \Phalcon\Db\RawValue('""');
			}
		} 
	 }
	 
	/**
	*	mysql错误输出
	*/
	public static function getSqlError( $obj ){
		foreach ($obj->getMessages() as $message) {
				echo "Message: ", $message->getMessage();
				echo "Field: ", $message->getField();
				echo "Type: ", $message->getType();
				echo "<hr>";
		}
	}

}
